Ext.define('Usws.view.channel.Channel', {
	extend: 'Ext.tree.Panel',
    xtype: 'Channel-Grid',
    store: 'Channel',
    title: '频道信息',
    stateId: 'channelStateGrid',
    layout:'column',
    useArrows: true,
    rootVisible: false,
    titleCollapse: true,
    collapsible: true,
    autoScroll: true,
    initComponent: function() {
       this.tbar = [
  	                  {
						  xtype: 'panel',
						  layout:'hbox',
	       	              border:false,
	       	              items:[
	       	            	      {xtype: 'button', text: '添加频道',  action: 'add', margin:'5 5 5 5'}
	       	            	    ]
					  }
  	            ];
       this.columns = [
        {
           xtype: 'treecolumn', //this is so we know which column will show the tree
           text: '频道名称',
           width:'28%',
           sortable: true,
           dataIndex: 'name'
       },{
           //we must use the templateheader component so we can use a custom tpl
          // xtype: 'templatecolumn',
           text: '角色',
           sortable: true,
           width:'20%',
           dataIndex: 'targetRole',
           align: 'center',
    	   renderer: function(value){
    		   var role="";
    		   if((value&4) === 4) {
               	   role += '公共频道/';
               }
               if ((value&1) === 1) {
            	   role += '学生/';
               }
               if((value&2) === 2) {
            	   role += '家长/';
               } 
               if((value&8) === 8) {
            	   role += '老师/';
               }
               var index = role.lastIndexOf("/");
               if(index != -1) {
            	   return role.substring(0, index);
               } else {
            	   return role;
               }
           }
       },{
           text: '类型',
           dataIndex: 'channelTypeDsid',
           width:'10%',
           align: 'center',
           renderer: function(value){
               if (value === 1) {
                   return '普通频道';
               } else if(value === 2) {
               	   return '功能';
               } else if(value === 3) {
               	   return '视频';
               } else if(value === 4) {
               	   return '会议';
               }
           }
       }
       ,{
           text: '添加视频',
           width:'10%',
           menuDisabled: true,
           xtype: 'actioncolumn',
           align: 'center',
           items: [{
	        	   icon: '/ext4/resources/images/add.gif',
	               tooltip: '添加视频',
	               action: 'addVedio',
	        	   handler: function(view, rowIndex, colIndex, item, e, record) {
	        		   this.fireEvent('itemclick', this, view, rowIndex, colIndex, item, e, record);
	               }
           }]
       },
       {
           text: '上下移动',
           menuDisabled: true,
           width:'15%',
           xtype: 'actioncolumn',
           align: 'center',
          
           items: [{
	        	   icon: '/ext4/resources/images/top2.gif',
	               tooltip: '置顶',
	               action: 'upTop',
	        	   handler: function(view, rowIndex, colIndex, item, e, record) {
	        		   this.fireEvent('itemclick', this, view, rowIndex, colIndex, item, e, record);
	               },
	               // Only leaf level tasks may be edited
	              isDisabled: function(view, rowIdx, colIdx, item, record) {
	                   return record.isFirst();
	               }
              },'-',{
                  icon: '/ext4/resources/images/up2.gif',
                  tooltip: '上移',
                  action: 'up',
                  handler: function(view, rowIndex, colIndex, item, e, record) {
                	  this.fireEvent('itemclick', this, view, rowIndex, colIndex, item, e, record);
                  },
                  isDisabled: function(view, rowIdx, colIdx, item, record) {
	                   return record.isFirst();
	               }
              },'-',{
                  icon: '/ext4/resources/images/down2.gif',
                  tooltip: '下移',
                  action: 'down',
                  handler: function(view, rowIndex, colIndex, item, e, record) {
                	  this.fireEvent('itemclick', this, view, rowIndex, colIndex, item, e, record);
                  },
                  isDisabled: function(view, rowIdx, colIdx, item, record) {
	                   return record.isLast();
	               }
              },'-',{
                  icon: '/ext4/resources/images/bottom2.gif',
                  tooltip: '置底',
                  action: 'downTail',
                  handler: function(view, rowIndex, colIndex, item, e, record) {
                	  this.fireEvent('itemclick', this, view, rowIndex, colIndex, item, e, record);
                  },
                  isDisabled: function(view, rowIdx, colIdx, item, record) {
	                   return record.isLast();
	               }
              }]
       }
       ,{
           text: '管理视频',
           width:'7%',
           menuDisabled: true,
           xtype: 'actioncolumn',
           align: 'center',
           items: [{
	        	   icon: '/ext4/resources/images/application_view_list.png',
	               tooltip: '查看视频',
	               action: 'listVedio',
	        	   handler: function(view, rowIndex, colIndex, item, e, record) {
	        		   this.fireEvent('itemclick', this, view, rowIndex, colIndex, item, e, record);
	               }
           }]
       },
       {
           text:'操作',
           xtype: 'actioncolumn',
           margin:'5px',
           align:'center',
           width : '8%',
           items: [{
           	icon: '/ext4/resources/images/cog_edit.png',  // Use a URL in the icon config
               tooltip: '编辑',
               action: 'edit',
               handler: function(view, rowIndex, colIndex, item, e, record) {
            	   this.fireEvent('itemclick', this, view, rowIndex, colIndex, item, e, record);
               }
           },'-',{
               icon: '/ext4/resources/images/delete.gif',
               tooltip: '删除',
               action: 'delete',
               handler: function(view, rowIndex, colIndex, item, e, record) {
            	   this.fireEvent('itemclick', this, view, rowIndex, colIndex, item, e, record);
               }
           }]
       }];
       this.callParent();
   }
});
